package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.AdminOrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Title: OrderController
 * @Author 贾金博
 * @Package com.sky.controller.admin
 * @Date 2024/3/30 20:33
 * @description:
 */


@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j

public class OrderController {

    @Autowired
    private AdminOrderService adminOrderService;

    /**
     * 订单查询 查询的是全部的订单
     */

    @GetMapping("/conditionSearch")
    @ApiOperation("订单查询")
    public Result<PageResult>conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        PageResult pageResult = adminOrderService.conditionSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 各个状态的订单数量统计
     * @return
     */
    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量统计")
    public Result<OrderStatisticsVO> statistics() {
        OrderStatisticsVO orderStatisticsVO = adminOrderService.statistics();
        return Result.success(orderStatisticsVO);
    }


    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @GetMapping("details/{id}")
    @ApiOperation("查询订单详情")
    public Result<OrderVO>details( @PathVariable Long id) {
        OrderVO orderVO = adminOrderService.findByOrderId(id);
        return Result.success(orderVO);
    }

    /**
     * 订单拒绝
     * @return
     */
    @PutMapping("rejection")
    @ApiOperation("订单拒绝")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        log.info("订单拒绝: {}", ordersRejectionDTO);
        adminOrderService.rejection(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 接单
     * @return
     */
    @PutMapping("confirm")
    @ApiOperation("接单")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        adminOrderService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 派送订单
     * @return
     */
    @PutMapping("delivery/{id}")
    @ApiOperation("派送订单")
    public Result delivery(@PathVariable Long id) {
        adminOrderService.delivery(id);
        return Result.success();
    }

    /**
     * 完成订单
     * @param id
     * @return
     */
    @PutMapping("complete/{id}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable Long id) {
        adminOrderService.complete(id);
        return Result.success();
    }

    /**
     * 取消订单
     * @param ordersCancelDTO
     * @return
     */
    @PutMapping("cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        adminOrderService.cancel(ordersCancelDTO);
        return Result.success();
    }
}
